package com.study.springbootsecurity.enums;

import lombok.AllArgsConstructor;
import lombok.Getter;

// 二维码的状态枚举类
@Getter
@AllArgsConstructor
public enum QrCodeStatus {
    WAITING_SCAN (1, "二维码初始状态二维码新建后设置状态:待扫码状态"),
    SCANNED_WAITING_CONFIRM(2, "二维码扫码后,待确认登录状态"),
    CONFIRMED(3, "二维码扫码后,用户确认授权状态"),
    CANCELED(4, "二维码扫码后,用户取消授权状态"),
    EXPIRED(5, "二维码过期状态");

    private final int code;
    private final String desc;

    /**
     * @param code 二维码状态编号
     * @return QrCodeStatus 二维码状态枚举类
     */
    public static QrCodeStatus getQrCodeStatusByCode(int code) {
        QrCodeStatus[] ecs = QrCodeStatus.values();
        for (QrCodeStatus ec : ecs) {
            if (ec.getCode() == code) {
                return ec;
            }
        }
        return null;
    }
}
